import React from 'react'
import { useLocation, useSearchParams } from 'react-router-dom';
import { Button, Cell } from 'react-vant';
import request from '../../utils/request';
function Index() {
    const location = useLocation()
    const v=location.state
      const date = localStorage.getItem("date");
   const [searchParams]=useSearchParams()
   const price =searchParams.get('price')
   const title =searchParams.get('title')
   const id =searchParams.get('id')
      //支付请求
      const pay=async()=>{
         const res=await request.get('/pay',{params:{price,title,id}}) 
         console.log(res.data)
         const {code,data}=res.data 
         if(code===200)
         {
             window.location.href=data
         }
      }
  return (
    <div>
       {/* 信息 */}
      <Cell
        title={
          <h4>
            <span>{date}</span>
            <span style={{ margin: "0px 5px" }}>{v.dst}</span>
            <span>
              {v.dasn} ---&gt; {v.aasn}{" "}
            </span>
          </h4>
        }
        label="二等座￥135"
        value="详情"
      ></Cell>

      <Button block round type='primary' onClick={()=>pay()}>立即支付</Button>
    </div>
  )
}

export default Index
